﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria.ID;

namespace Terraria.ModLoader
{
	// Token: 0x0200020F RID: 527
	public static class MountLoader
	{
		// Token: 0x0600171B RID: 5915 RVA: 0x00011952 File Offset: 0x0000FB52
		public static ModMountData GetMount(int type)
		{
			if (MountLoader.mountDatas.ContainsKey(type))
			{
				return MountLoader.mountDatas[type];
			}
			return null;
		}

		// Token: 0x0600171C RID: 5916 RVA: 0x004178E8 File Offset: 0x00415AE8
		internal static int ReserveMountID()
		{
			if (ModNet.AllowVanillaClients)
			{
				throw new Exception("Adding mounts breaks vanilla client compatiblity");
			}
			int result = MountLoader.nextMount;
			MountLoader.nextMount++;
			return result;
		}

		// Token: 0x0600171D RID: 5917 RVA: 0x0001196E File Offset: 0x0000FB6E
		internal static void ResizeArrays()
		{
			Array.Resize<bool>(ref MountID.Sets.Cart, MountLoader.nextMount);
			Array.Resize<Mount.MountData>(ref Mount.mounts, MountLoader.nextMount);
		}

		// Token: 0x0600171E RID: 5918 RVA: 0x0001198E File Offset: 0x0000FB8E
		internal static void Unload()
		{
			MountLoader.mountDatas.Clear();
			MountLoader.nextMount = 15;
		}

		// Token: 0x0600171F RID: 5919 RVA: 0x000119A1 File Offset: 0x0000FBA1
		internal static bool IsModMountData(Mount.MountData mountData)
		{
			return mountData.modMountData != null;
		}

		// Token: 0x06001720 RID: 5920 RVA: 0x000119AC File Offset: 0x0000FBAC
		internal static void SetupMount(Mount.MountData mount)
		{
			if (MountLoader.IsModMountData(mount))
			{
				MountLoader.GetMount(mount.modMountData.Type).SetupMount(mount);
			}
		}

		// Token: 0x06001721 RID: 5921 RVA: 0x000119CC File Offset: 0x0000FBCC
		public static void JumpHeight(Mount.MountData mount, ref int jumpHeight, float xVelocity)
		{
			if (MountLoader.IsModMountData(mount))
			{
				mount.modMountData.JumpHeight(ref jumpHeight, xVelocity);
			}
		}

		// Token: 0x06001722 RID: 5922 RVA: 0x000119E3 File Offset: 0x0000FBE3
		public static void JumpSpeed(Mount.MountData mount, ref float jumpSpeed, float xVelocity)
		{
			if (MountLoader.IsModMountData(mount))
			{
				mount.modMountData.JumpSpeed(ref jumpSpeed, xVelocity);
			}
		}

		// Token: 0x06001723 RID: 5923 RVA: 0x000119FA File Offset: 0x0000FBFA
		internal static void UpdateEffects(Player mountedPlayer)
		{
			if (MountLoader.IsModMountData(Mount.mounts[mountedPlayer.mount.Type]))
			{
				MountLoader.GetMount(mountedPlayer.mount.Type).UpdateEffects(mountedPlayer);
			}
		}

		// Token: 0x06001724 RID: 5924 RVA: 0x00011A2A File Offset: 0x0000FC2A
		internal static bool UpdateFrame(Player mountedPlayer, int state, Vector2 velocity)
		{
			return !MountLoader.IsModMountData(Mount.mounts[mountedPlayer.mount.Type]) || MountLoader.GetMount(mountedPlayer.mount.Type).UpdateFrame(mountedPlayer, state, velocity);
		}

		// Token: 0x06001725 RID: 5925 RVA: 0x00011A5E File Offset: 0x0000FC5E
		internal static bool CustomBodyFrame(Mount.MountData mount)
		{
			return MountLoader.IsModMountData(mount) && mount.modMountData.CustomBodyFrame();
		}

		// Token: 0x06001726 RID: 5926 RVA: 0x00011A78 File Offset: 0x0000FC78
		public static void UseAbility(Player player, Vector2 mousePosition, bool toggleOn)
		{
			if (MountLoader.IsModMountData(player.mount._data))
			{
				player.mount._data.modMountData.UseAbility(player, mousePosition, toggleOn);
			}
		}

		// Token: 0x06001727 RID: 5927 RVA: 0x00011AA4 File Offset: 0x0000FCA4
		public static void AimAbility(Mount mount, Player player, Vector2 mousePosition)
		{
			if (MountLoader.IsModMountData(mount._data))
			{
				mount._data.modMountData.AimAbility(player, mousePosition);
			}
		}

		// Token: 0x040015DF RID: 5599
		private static int nextMount = 15;

		// Token: 0x040015E0 RID: 5600
		internal static readonly IDictionary<int, ModMountData> mountDatas = new Dictionary<int, ModMountData>();
	}
}
